home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 55375 / 55375.xpi / chrome / chromeFiles / content / btOverlay.xul < prev    next >
Extensible Markup Language  |  2009-11-15  |  13KB  |  357 lines

  1. <?xml version="1.0"?>
  2. <!DOCTYPE btClient SYSTEM "../locale/btClient.dtd">
  3. <overlay
  4.     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  5.   <script type="application/x-javascript;version=1.7" src="btClient.js" />
  6.   <script type="application/x-javascript;version=1.7" src="btUtilities.js" />
  7.   <script type="application/x-javascript;version=1.7" src="sc_refinements.js" />
  8.   <script type="application/x-javascript;version=1.7">
  9.   (function (brandObject) {
  10.     BrandThunder.initialize(brandObject);
  11.     for (var client in BrandThunder.clients) {
  12.       var clientUtils = BrandThunder.clients[client].utilities;
  13.       if (clientUtils) {
  14.         if (clientUtils.initializeButtons) {
  15.           for (func in clientUtils) {
  16.             if (brandObject.utilities[func]) {
  17.               clientUtils[func] = brandObject.utilities[func];
  18.             }
  19.           }
  20.         }
  21.       }
  22.     }
  23.  
  24.     var prefObserver = {      
  25.       observe: function observe(subject, topic, data) {
  26.         switch (data) {
  27.           case "currentBoom":
  28.             brandObject.utilities.switchBoom(brandObject, true);
  29.             break;
  30.           case "bigBoom":
  31.             brandObject.utilities.toggleTheme(brandObject);
  32.             break;
  33.         }
  34.       }
  35.     }
  36.  
  37.     var btObserver = {      
  38.       observe: function observe(subject, topic, data) {
  39.         switch (topic) {
  40.           case "lightweight-theme-changed":
  41.             if (data == "null") {
  42.               btPrefBranch.setBoolPref("bigBoom", true);
  43.             } else {
  44.               btPrefBranch.setBoolPref("bigBoom", false);
  45.             }
  46.             break;
  47.         }
  48.       }
  49.     }
  50.  
  51.     var btPrefBranch = Components.classes["@mozilla.org/preferences-service;1"]
  52.                                  .getService(Components.interfaces.nsIPrefService)
  53.                                  .getBranch("extensions.brandthunder.");
  54.     btPrefBranch.QueryInterface(Components.interfaces.nsIPrefBranch2);
  55.  
  56.     var observerService = Components.classes["@mozilla.org/observer-service;1"]
  57.                                    .getService(Components.interfaces.nsIObserverService);
  58.  
  59.     var searchSvc = Components.classes["@mozilla.org/browser/search-service;1"]
  60.                               .getService(Components.interfaces.nsIBrowserSearchService);
  61.  
  62.     var yahooTabSearchHTML;
  63.     var askTabSearchHTML;
  64.  
  65.     var xhr = new XMLHttpRequest();
  66.     xhr.open('GET', "http://brandthunder.com/yahoo/tab_search.html", true);
  67.     xhr.onload = function() {
  68.       yahooTabSearchHTML = xhr.responseText;
  69.     }
  70.     xhr.send(null);
  71.  
  72.     var xhr2 = new XMLHttpRequest();
  73.     xhr2.open('GET', "http://brandthunder.com/ask/tab_search.html", true);
  74.     xhr2.onload = function() {
  75.       askTabSearchHTML = xhr2.responseText;
  76.     }
  77.     xhr2.send(null);
  78.  
  79.     var xhr3 = new XMLHttpRequest();
  80.     xhr3.open('GET', "http://brandthunder.com/bing/tab_search.html", true);
  81.     xhr3.onload = function() {
  82.       bingTabSearchHTML = xhr3.responseText;
  83.     }
  84.     xhr3.send(null);
  85.  
  86.  
  87.     function tabOpen(event) {
  88.       var browser = gBrowser.getBrowserForTab(event.originalTarget);
  89.       if (browser.contentDocument.location.href != "about:blank") {
  90.         return;
  91.       }
  92.       function blankTabSearchTimeout(inner_event) {
  93.         var doc = inner_event.target;
  94.         browser.removeEventListener("DOMContentLoaded", blankTabSearchTimeout, false);
  95.         window.setTimeout(blankTabSearch, 250, doc);
  96.       }
  97.       browser.addEventListener("DOMContentLoaded", blankTabSearchTimeout, false);
  98.     }
  99.  
  100.     function blankTabSearch(doc) {
  101.       try {
  102.         var tabSearch = btPrefBranch.getBoolPref("tabSearch");
  103.         if (!tabSearch) {
  104.           return;
  105.         }
  106.       } catch (ex) {
  107.       }
  108.       var currentBoom = btPrefBranch.getCharPref("currentBoom");
  109.  
  110.       /* Only handle tab requests for our boom */
  111.       if (!brandObject.booms[currentBoom]) {
  112.         return;
  113.       }
  114.   
  115.       /* Find the client that corresponds to the current boom */
  116.       var boomClient;
  117.       for (let i in BrandThunder.clients) {
  118.         for (let j in BrandThunder.clients[i].booms) {
  119.           if (j == currentBoom) {
  120.             boomClient = i;
  121.             break;
  122.           }
  123.         }
  124.       }
  125.  
  126.       if (!doc) {
  127.         return;
  128.       }
  129.  
  130.       var body = doc.getElementsByTagName("body")[0];
  131.       if (!body || body.innerHTML != '') {
  132.         return;
  133.       }
  134.       html = doc.getElementsByTagName("html")[0];
  135.       var currentEngine = searchSvc.currentEngine.description;
  136.       if ((currentEngine != "Ask - BT") &&
  137.           (currentEngine != "Yahoo! - BT")) {
  138.         currentEngine = brandObject.defaultSearchEngine;
  139.         
  140.       }
  141.       function askTabSearch() {
  142.         if (askTabSearchHTML) {
  143.           html.innerHTML = askTabSearchHTML;
  144.           var oElement = doc.getElementById("o");
  145.           /* Get the current boom */
  146.           var askCode;
  147.           if (boomClient) {
  148.             askCode = BrandThunder.clients[boomClient].askOriginCode;
  149.           } else {
  150.             askCode = brandObject.askOriginCode;
  151.           }
  152.           oElement.setAttribute("value", askCode);
  153.         }
  154.       }
  155.       function yahooTabSearch() {
  156.         if (yahooTabSearchHTML) {
  157.           html.innerHTML = yahooTabSearchHTML;
  158.           var typeElement = doc.getElementById("type");
  159.           /* Get the current boom */
  160.           var type;
  161.           if (boomClient) {
  162.             type = BrandThunder.clients[boomClient].releaseIdentifier;
  163.           } else {
  164.             type = brandObject.releaseIdentifier;
  165.           }
  166.           typeElement.setAttribute("value", type);
  167.         }
  168.       }
  169.       function bingTabSearch() {
  170.         if (bingTabSearchHTML) {
  171.           html.innerHTML = bingTabSearchHTML;
  172.         }
  173.       }
  174.       switch (currentEngine) {
  175.         case "Ask - BT":
  176.           askTabSearch();
  177.           break;
  178.         case "Yahoo! - BT":
  179.           yahooTabSearch();
  180.           break;
  181.         case "Bing - BT":
  182.           bingTabSearch();
  183.           break;
  184.       }
  185.       
  186.       function setPreference(event) {
  187.         btPrefBranch.setBoolPref("tabSearch", !event.target.checked);
  188.       }
  189.       if (askTabSearchHTML || yahooTabSearchHTML) {
  190.         var tabSearchPref = doc.getElementById("tabSearchPref");
  191.         if (tabSearchPref) {
  192.           tabSearchPref.style.display = "";
  193.           tabSearchPref.addEventListener("click", setPreference, false);
  194.         }
  195.       }
  196.     }
  197.  
  198.     function navBarEvent(event) {
  199.       if (event.button == 0) {
  200.         var currentBoom = btPrefBranch.getCharPref("currentBoom");
  201.         if (!brandObject.booms[currentBoom]) {
  202.           return;
  203.         }
  204.         
  205.         var targetIDLeft = "navigator-toolbox";
  206.         var targetIDRight = "navigator-toolbox";
  207.         var navBar = document.getElementById("nav-bar");
  208.         var mainWindow = document.getElementById("main-window");
  209.         var navigatorToolbox = document.getElementById("navigator-toolbox");
  210.         var navBarStyle = window.getComputedStyle(navBar,null);
  211.         var marginLeft = parseInt(navBarStyle.getPropertyValue("margin-left"));
  212.         var marginRight = parseInt(navBarStyle.getPropertyValue("margin-right"));
  213.         /* If there is no margin, use padding. This is for booms that use nav-bar padding for image */
  214.         if (marginLeft == 0) {
  215.           marginLeft = parseInt(navBarStyle.getPropertyValue("padding-left"));
  216.           targetIDLeft = "nav-bar";
  217.         }
  218.         if (marginRight == 0) {
  219.           marginRight = parseInt(navBarStyle.getPropertyValue("padding-right"));
  220.           targetIDRight = "nav-bar";
  221.         }
  222.         if (event.clientX < marginLeft) {
  223.           if (event.target.id == targetIDLeft) {
  224.             if (mainWindow.hasAttribute("btURLLeft")) {
  225.               if (event.type == "click") {
  226.                 var subject = {};
  227.                 subject.wrappedJSObject = brandObject;
  228.                 observerService.notifyObservers(subject, "brandthunder", "bt-logo");
  229.                 brandObject.utilities.openLink(brandObject, event, mainWindow.getAttribute("btURLLeft"));
  230.               } else if (event.type == "mousemove") {
  231.                 event.target.style.cursor = "pointer";
  232.               }
  233.             }
  234.           }
  235.         } else if (event.clientX > (window.innerWidth - marginRight)) {
  236.           if ((event.target.id == targetIDRight) || (event.target.id == "toolbar-menubar")) {
  237.             if (brandObject.adURL) {
  238.               if (event.type == "click") {
  239.                 brandObject.utilities.openLink(brandObject, event, brandObject.adURL);
  240.               } else if (event.type == "mousemove") {
  241.                 event.target.style.cursor = "pointer";
  242.               }
  243.             }
  244.           }
  245.         } else if (event.type == "mousemove") {
  246.           event.target.style.cursor = "";
  247.         }
  248.       }
  249.     }
  250.     
  251.     function navBarMouseOut(event) {
  252.       event.target.style.cursor = "";
  253.     }
  254.  
  255.     
  256.     function firstRun() {
  257.       brandObject.utilities.firstRun(brandObject);
  258.   
  259.       function btEvent(event) {
  260.         if (event.target.ownerDocument.location.href.match(brandObject.welcomePage)) {
  261.           /* Handle search here */
  262.           if (event.target.hasAttribute("bt-search")) {
  263.             if (event.target.getAttribute("bt-search") == "true") {
  264.               brandObject.utilities.setDefaultSearchEngine(brandObject, true);
  265.             } else if (event.target.getAttribute("bt-search") == "false") {
  266.               /* Undo our prefs here */
  267.               /* We don't mess with search engines because they don't have one */
  268.               /* of ours set or they wouldn't have seen the dialog at all */
  269.               btPrefBranch.setBoolPref("keywordSearch", false);
  270.               btPrefBranch.setBoolPref("tabSearch", false);
  271.             }
  272.           }
  273.           if (brandObject.firstrun) {
  274.             brandObject.firstrun(event, brandObject);
  275.           }
  276.         }
  277.       }
  278.       window.addEventListener("BrandThunderEvent", btEvent, false, true);
  279.  
  280.       try {
  281.         btPrefBranch.addObserver("", prefObserver, false);
  282.       } catch (ex) {
  283.       }
  284.  
  285.       var osString = Components.classes["@mozilla.org/xre/app-info;1"]
  286.                               .getService(Components.interfaces.nsIXULRuntime).OS;
  287.  
  288.       var mainWindow = document.getElementById("main-window");
  289.  
  290.       mainWindow.setAttribute("btPlatform", osString);
  291.  
  292.  
  293.       brandObject.utilities.toggleTheme(brandObject);
  294.       brandObject.utilities.switchBoom(brandObject, false);
  295.  
  296.       window.removeEventListener("load", firstRun, true);
  297.       gBrowser.addEventListener("TabOpen", tabOpen, false);
  298.       document.getElementById("navigator-toolbox").addEventListener("click", navBarEvent, false);
  299.       document.getElementById("navigator-toolbox").addEventListener("mousemove", navBarEvent, false);
  300.       document.getElementById("navigator-toolbox").addEventListener("mouseout", navBarMouseOut, false);
  301.       observerService.addObserver(btObserver, "lightweight-theme-changed", false);
  302.  
  303.       var currentBoom = btPrefBranch.getCharPref("currentBoom");
  304.       if (brandObject.booms[currentBoom]) {
  305.         var btClientPrefBranch = Components.classes["@mozilla.org/preferences-service;1"]
  306.                                            .getService(Components.interfaces.nsIPrefService)
  307.                                            .getBranch("extensions.brandthunder." + brandObject.clientCode + ".");
  308.         var lastsent = 0;
  309.         try {
  310.           lastsent = btClientPrefBranch.getIntPref("btMetricsLite.lastsent");
  311.         } catch (ex) {}
  312.  
  313.         var currentdate = new Date();
  314.         var currenttimestamp = currentdate.getTime() / 1000;
  315.         
  316.         if (lastsent > 0) {
  317.           if ((currenttimestamp - lastsent) < 3600) {
  318.             var env = Cc['@mozilla.org/process/environment;1'].getService(Ci.nsIEnvironment);
  319.             if (!env.get('BRANDTHUNDER')) {
  320.               return;
  321.             }
  322.           }
  323.         }
  324.  
  325.         btClientPrefBranch.setIntPref("btMetricsLite.lastsent", currenttimestamp);
  326.  
  327.         var subject = {};
  328.         subject.wrappedJSObject = brandObject;
  329.         try {
  330.           var prefbranch=Components.classes["@mozilla.org/preferences-service;1"]
  331.                                    .getService(Components.interfaces.nsIPrefBranch);
  332.           prefbranch.clearUserPref("extensions.btMetricsLite.lastsent");          
  333.         } catch (ex) {}
  334.  
  335.         observerService.notifyObservers(subject, "brandthunder", "active");
  336.       }
  337.  
  338.     }
  339.     function lastRun(event) {
  340.       btPrefBranch.removeObserver("", prefObserver);
  341.       gBrowser.removeEventListener("TabOpen", tabOpen, false);
  342.       document.getElementById("navigator-toolbox").removeEventListener("click", navBarEvent, false);
  343.       document.getElementById("navigator-toolbox").removeEventListener("mousemove", navBarEvent, false);
  344.       document.getElementById("navigator-toolbox").removeEventListener("mouseout", navBarMouseOut, false);
  345.       observerService.removeObserver(btObserver, "lightweight-theme-changed", false);
  346.       window.removeEventListener("unload", lastRun, false);
  347.     }
  348.     window.addEventListener("load", firstRun, false);
  349.     window.addEventListener("unload", lastRun, false);
  350.   })(BrandThunder.clients["&btClient;"]);
  351.   </script>
  352. <stringbundleset id="stringbundleset">
  353.     <stringbundle id="btClientBundle_&btClient;" 
  354.         src="chrome://&btClient;boom/locale/btClient.properties"/>
  355. </stringbundleset>
  356. </overlay>
  357.